import React, { Component } from "react";
import { connect } from 'react-redux'
import { actionCreators } from './store'
import style from './style.module.css'
import { Redirect } from 'react-router-dom';
class Login extends Component {

    render() {
        const { login } = this.props;
        console.log(1213, login)
        if (!login) {
            return (<div className={style.LoginPositon}>
                <div>
                 
                </div>
                <div className={style.LoginForm}>
                    <input placeholder="账号" ref={(input) => { this.accout = input }} />
                    <input placeholder="密码" ref={(input) => { this.psd = input }} />
                    <button onClick={() => this.props.handleLogin(this.accout, this.psd)}>登录</button>
                </div>
            </div>)
        } else {
            return <Redirect to="/" />
        }

    }

}
const mapStateToProps = (state, ownProps) => {
    return {
        login: state.getIn(["login", "login"])
    }
}
const mapDispatchToProps = (dispatch, ownProps) => {
    return {
        handleLogin: (accont, psd) => {
            console.log(1213, accont.value, psd.value)
            let form = {
                accont: accont.value,
                psd: psd.value
            }
            dispatch(actionCreators.login(form))
        }
    }
}
export default connect(mapStateToProps, mapDispatchToProps)(Login)